<?php
require(dirname(__FILE__)."/includes/init.php");
if(isset($_SESSION['user_name'])){
$perPageNum = $GLOBALS['pageSize'];
$pageNum = isset($_REQUEST['pg'])?$_REQUEST['pg']:1;
$id = NULL;
$listArr = checkTempTemplate($id,$pageNum);
if (isset($_REQUEST['id'])) {
	delTempTemplate($_REQUEST['id']);
	echo "<script>alert('del');location.href ='checkTempTemplate.php';</script>";
}

if(isset($_REQUEST['clear'])){
    if(clearTempTemplate()){
		echo "<script>alert('clear successful');location.href ='checkTempTemplate.php';</script>";
	}
}
if(isset($_REQUEST['del'])){
    delOk();
	echo "del success!";
}
if(isset($_REQUEST['Submit'])){
    $testId = $_REQUEST['testId'];
	$testEmail = $_REQUEST['testEmail'];
	$testServer = $_REQUEST['testServer'];
	$sql = "select * from tempTemplate where id = ".$testId."";
	$rowResult = $GLOBALS['db']->dbGetRow($sql);
	send_simple_message($testEmail, $rowResult['title'], $rowResult['content'], $rowResult['id'], $serverArr[$testServer]);
}
?><title>邮件生成列表</title>
<table width="1263" height="147" border="0" bgcolor="#0066FF" style="font-size:12px">
<form action="checkTempTemplate.php" method="post" name="checkTempTemplate">
  <tr bgcolor="#FFFFFF">
    <td>ID</td>
    <td><input type="text" name="testId" /></td>
    <td>Email:
    <input type="text" name="testEmail" /> </td>
    <td>Server:</td>
    <td><input name="testServer" type="text" id="testServer" /></td>
    <td><input type="submit" name="Submit" value="提交" /></td>
    <td><a href="checkTempTemplate.php?del=delok">删除已发</a></td>
    <td><a href="checkTempTemplate.php?del=delok"></a></td>
  </tr>
</form>  
  <tr bgcolor="#FFFFFF">
    <td width="93">id</td>
    <td width="230">address</td>
    <td width="606" colspan="3">title</td>
    <td width="73">类型</td>
    <td width="63">状态</td>
    <td width="172">操作 <a href="checkTempTemplate.php?clear=clear">清空</a></td>
  </tr>
 <?php foreach($listArr as $key=>$value){?>   
  <tr bgcolor="#FFFFFF">
    <td><?php echo $value['id'];?></td>
    <td><?php echo $value['address'];?></td>
    <td colspan="3"><?php echo $value['title'];?></td>
    <td><?php echo $value['type'];?></td>
    <td><?php echo $value['flag'];?></td>
    <td><a href="viewTempTemplate.php?id=<?php echo $value['id'];?>" target="_blank">查看</a> &nbsp;&nbsp;&nbsp;&nbsp; <a href="checkTempTemplate.php?id=<?php echo $value['id'];?>" target="_blank">删除</a></td>
  </tr>
 <?php }?> 
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td colspan="6"><?php $totalNum = getTempTemplateNum();
		$page = new Pager($totalNum[0],$perPageNum,$style="page");

	?></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>剩余量:</td>
    <td colspan="6"><?php 
	$sql = "select count(*) as num,type from tempTemplate where flag = 0 group by type";
	$restNum = $GLOBALS['db']->dbfetchAll($sql);
	foreach($restNum as $value){
		echo " |||| Type:".$value['type']." Num: ".$value['num']." |||| ";
	}
	?></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>已发送:</td>
    <td colspan="6"><?php 
	$sql = "select count(*) as num,type from tempTemplate where flag = 1 group by type";
	$restNum = $GLOBALS['db']->dbfetchAll($sql);
	foreach($restNum as $value){
		echo " |||| Type:".$value['type']." Num: ".$value['num']." |||| ";
	}
	?></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td colspan="6"><?php include("includes/symbolic.htm");?></td>
    <td>&nbsp;</td>
  </tr>
</table>
<?php
}else{
 echo "hello";
}
?>